package com.zzyl.controller;


import com.github.pagehelper.Page;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing")
@Api(value = "护理计划管理")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 查询所有护理计划
     * @return ResponseResult
     */
    @GetMapping("/plan")
    @ApiOperation(value = "查询所有护理计划")
    public ResponseResult<List<NursingPlanVo>> getByAll(){
        List<NursingPlanVo> all = nursingPlanService.getByAll();
        return ResponseResult.success(all);
    }

    /**
     * 分页查询
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/plan/search")
    @ApiOperation(value = "分页查询")
    public ResponseResult<PageResponse<NursingPlanVo>> getByPage(String name, Integer pageNum, Integer pageSize, Integer status){
        PageResponse<NursingPlanVo> page = nursingPlanService.getByPage(name, pageNum, pageSize, status);
        return ResponseResult.success(page);
    }
    /**
     * 添加护理计划
     * @param nursingPlanDto
     * @return
     */
    @PostMapping("/plan")
    @ApiOperation(value = "添加护理计划")
    public ResponseResult add(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.add(nursingPlanDto);
        return ResponseResult.success();
    }

    /**\
     *  查询护理计划详情
     * @param id
     * @return
     */
    @GetMapping("/plan/{id}")
    @ApiOperation(value = "查询护理计划详情")
    public ResponseResult<NursingPlanVo> getById(@PathVariable Long id){
        NursingPlanVo nursingPlanVo = nursingPlanService.getById(id);
        return ResponseResult.success(nursingPlanVo);
    }

    /**
     * 修改护理计划
     * @param id
     * @param nursingPlanDto
     * @return
     */
    @PutMapping("/plan/{id}")
    @ApiOperation(value = "修改护理计划")
    public ResponseResult update(@PathVariable Long id, @RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanDto.setId(id);
        nursingPlanService.update(nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     * 删除护理计划
     * @param id
     * @return
     */
    @DeleteMapping("/plan/{id}")
    @ApiOperation(value = "删除护理计划")
    public ResponseResult delete(@PathVariable Long id){
        nursingPlanService.delete(id);
        return ResponseResult.success();
    }



    @PutMapping("plan/{id}/status/{status}")
    @ApiOperation(value = "启用/禁用护理计划")
    public ResponseResult enableOrDisable(@PathVariable(value = "id") Long id,
                                          @PathVariable(value = "status") Integer status){
        nursingPlanService.enableOrDisable(id, status);
        return ResponseResult.success();
    }

}
